﻿using CatUtils.Utils.SpecialUtils.View;
using CatUtilsDll.Utils.Currency.WebUtils;
using System;
using System.ComponentModel;
using System.Net;
using System.Windows.Forms;

namespace CatUtils.Utils.SpecialUtils.Update
{
    internal class UpgradeProgramHelper
    {
        private Label LocalLable = null;

        public void DownloadUpdate(string UpdateUrl, Label TipLable)
        {
            LocalLable = TipLable;
            WebHeaderCollection webHeaderCollection = new WebHeaderCollection
            {
                { "User-Agent",WebHelper.UserAgentPC },

                { "Accept-Language", "zh-TW,zh;q=0.8,en-US;q=0.5,en;q=0.3" }
            };
            WebHelper.DownloadToFileAsync(UpdateUrl, System.IO.Path.GetTempFileName(),
                    webHeaderCollection, DownloadComplted, DownloadProceress);
        }

        private void DownloadProceress(object sender, DownloadProgressChangedEventArgs e)
        {
            Console.WriteLine(e.ProgressPercentage);
            new ViewAsyncUpdate().LableUpdateTextAsync(LocalLable, $"下载进度{e.ProgressPercentage}%");
        }

        private void DownloadComplted(object sender, AsyncCompletedEventArgs e)
        {
            MessageBox.Show("s");
            Console.WriteLine(e.Cancelled);
            Console.WriteLine(e.Error);
            Console.WriteLine(e.UserState);
        }
    }
}